package cn.luoshaocheng.basic.service.impl;

import cn.luoshaocheng.basic.service.IBaseService;
import cn.luoshaocheng.basic.mapper.BaseMapper;
import cn.luoshaocheng.basic.query.BaseQuery;
import cn.luoshaocheng.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public abstract class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;


    @Override
    @Transactional//默认只读为false，默认传播机制为REQUIRED[有且仅有一个事务]
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional//默认只读为false，默认传播机制为REQUIRED[有且仅有一个事务]
    public void delete(Long id) {
        baseMapper.remove(id);
    }

    @Override
    @Transactional//默认只读为false，默认传播机制为REQUIRED[有且仅有一个事务]
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        //总条数
        Integer count = baseMapper.queryCount(query);
        //每一条数据
        List<T> rows = baseMapper.queryData(query);
        //装的就是分页的数据
        return new PageList<T>(count, rows);
    }

    //批量删除
    @Override
    @Transactional
    public void patchDel(List<Long> ids) {
        baseMapper.patchDel(ids);
    }



}

